import type { FieldRule } from 'vant'

// 校验规则工具文件
// 手机号的校验规则
export const MobileRules: FieldRule[] = [
  { required: true, message: '手机号不能为空', trigger: 'onChange' },
  {
    pattern: /^1[3-9]\d{9}$/,
    message: '请输入正确格式的手机号',
    trigger: 'onChange'
  }
]
// 密码的校验规则
export const PasswordRules: FieldRule[] = [
  { required: true, message: '密码不能为空', trigger: 'onChange' },
  {
    pattern: /^\w{8,24}$/,
    message: '密码在8-24个字符之间',
    trigger: 'onChange'
  }
]
// 验证码的校验规则
export const CodeRules: FieldRule[] = [
  { required: true, message: '验证码不能为空', trigger: 'onChange' },
  { pattern: /^\d{6}$/, message: '验证码为6位数字', trigger: 'onChange' }
]

// 中文姓名的校验规则
export const NameRules: FieldRule[] = [
  { required: true, message: '姓名不能为空', trigger: 'onChange' },
  {
    pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    message: '名称输入不正确',
    trigger: 'onChange',
    validateEmpty: false // 对空值不校验
  }
]
// 身份证号的校验规则
export const IdRules: FieldRule[] = [
  { required: true, message: '身份证不能为空', trigger: 'onChange' },
  {
    pattern:
      /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '请输入正确的18位身份证',
    trigger: 'onChange',
    validateEmpty: false // 对空值不校验
  }
]
